//万恶的分页 start

$(function (){

    //默认显示数据开始位置
    let pager_num = 0
    let pager_num_ceil =1
    $("#pager_input").val(1)
    //获取数据总数
    $.ajax({
        url: 'http://152.136.97.131:10021/auth/api/dic/searchDic',
        data: {
            offset: 1,
            limit: 1,
        },
        type:'post',
        dataType: 'json',
        headers: {'authorities': 'aaa89976-ee44-4bad-a5e5-b0540311d1ed'},
        success:function (e){
            $("#data_number").text(e.total)
            pager_num_offset = Math.ceil(e.total/10)
            pager_offset = e.total
        }
    })
//    下一页按钮点击事件
    $("#rarr").click(function (){
        if (pager_num < pager_offset-10){
            pager_num= pager_num+10
            $("#pager_input").val(Math.ceil($("#pager_input").val())+1)
            $("#data-list").empty();
            $.ajax({
                url: 'http://152.136.97.131:10021/auth/api/dic/searchDic',
                data: {
                    offset : pager_num,
                    limit:10,
                },
                type:'post',
                headers: {'authorities': 'aaa89976-ee44-4bad-a5e5-b0540311d1ed'},
                success:function (c){
                    for(let i=0;i<10;i++){
                        $("#data-list").append(
                            '<tr><td class="sn">'+c.content[i].uuid+'</td><td class="title">'+c.content[i].dicgroup+'</td> <td class="grade">'
                            +c.content[i].dickey+'</td><td class="">'+c.content[i].dicvalue+'</td><td class="">'+c.content[i].state+'</td> <td class="">'+c.content[i].revision+'</td>' +
                            '<td><a data-toggle="modal" class="modify-modal" href="#modify">修改 </a><a class="del"> 删除</a></td></tr>'
                        )
                    }
                }
            })
        }

    })
//    上一页按钮点击事件
    $("#larr").click(function (){
        if(pager_num > 0){
            pager_num = pager_num-10
            $("#pager_input").val(Math.ceil($("#pager_input").val())-1)
            $("#data-list").empty();
            $.ajax({
                url: 'http://152.136.97.131:10021/auth/api/dic/searchDic',
                data: {
                    offset : pager_num,
                    limit:10,
                },
                type:'post',
                headers: {'authorities': 'aaa89976-ee44-4bad-a5e5-b0540311d1ed'},
                success:function (c){
                    console.log(c);
                    $("#data-list").empty();
                    for(let i=0;i<10;i++){
                        $("#data-list").append(
                            '<tr><td class="sn">'+c.content[i].uuid+'</td><td class="title">'+c.content[i].dicgroup+'</td> <td class="grade">'
                            +c.content[i].dickey+'</td><td class="">'+c.content[i].dicvalue+'</td><td class="">'+c.content[i].state+'</td> <td class="">'+c.content[i].revision+'</td>' +
                            '<td><a data-toggle="modal" class="modify-modal" href="#modify">修改 </a><a class="del"> 删除</a></td></tr>'
                        )
                    }
                }
            })
        }

    })
//    页码失焦时根据页码跳转
    $("#pager_input").blur(function() {
        let rr =$("#pager_input").val()
        if(rr > 0){
            if(rr <= pager_num_offset){
                let rrn = (rr*10)-10
                pager_num = rrn
                $("#data-list").empty();
                $.ajax({
                    url: 'http://152.136.97.131:10021/auth/api/dic/searchDic',
                    data: {
                        offset : rrn,
                        limit:10,
                    },
                    type:'post',
                    headers: {'authorities': 'aaa89976-ee44-4bad-a5e5-b0540311d1ed'},
                    success:function (c){
                        for(let i=0;i<10;i++){
                            $("#data-list").append(
                                '<tr><td class="sn">'+c.content[i].uuid+'</td><td class="title">'+c.content[i].dicgroup+'</td> <td class="grade">'
                                +c.content[i].dickey+'</td><td class="">'+c.content[i].dicvalue+'</td><td class="">'+c.content[i].state+'</td> <td class="">'+c.content[i].revision+'</td>' +
                                '<td><a data-toggle="modal" class="modify-modal" href="#modify">修改 </a><a class="del"> 删除</a></td></tr>'
                            )
                        }
                    }
                })
            }
            else  if(rr > pager_num_offset){
                alert("没有这么多页")
            }
        }
        else if(rr<0){
            alert("请输入大于0的数")
        }
    });
})
//万恶的分页 end